package com.ljsw.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ljsw.activity.R;

/**
 * Created by Administrator on 2018/1/4.
 */

public class HuiKuPassDialog {
    public HuiKuPassDialog(Context context) {
        super();
        this.context = context;
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();//获取屏幕分辨率
    }
    private Context context;
    private Dialog dialog;
    private Display display;
    private LinearLayout lLayout_bg;
    private TextView delete_title;//标题
    private Button queding,quxiao;//确定|取消


    public HuiKuPassDialog builder(){
        // 获取Dialog布局
        View view = LayoutInflater.from(context).inflate(R.layout.view_deletedialog, null);
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
        delete_title = (TextView) view.findViewById(R.id.delete_title);
        queding = (Button) view.findViewById(R.id.queding_delete);
        quxiao = (Button) view.findViewById(R.id.quxiao_delete);
        //添加Dialog样式
        dialog = new Dialog(context, R.style.DeleteDialog);
        dialog.setContentView(view);
        // 调整dialog背景大小
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT));
        return this;
    }
    /**
     * 设置标题
     * @param title
     * @return
     */
    public HuiKuPassDialog setTitle(String title){
        delete_title.setText(title);
        return this;
    }

    public HuiKuPassDialog setOnlyButton(){
        quxiao.setVisibility(View.GONE);
        return this;
    }

    public HuiKuPassDialog setkeyListener(DialogInterface.OnKeyListener listener){
        dialog.setOnKeyListener(listener);
        dialog.setCancelable(false);
        return this;
    }

    /**
     * 取消事件
     * @param text
     * @param listener
     * @return
     */
    public HuiKuPassDialog setNegativeButton(String text,
                                             final View.OnClickListener listener) {
        quxiao.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                listener.onClick(v);
                dialog.dismiss();
            }
        });
        return this;
    }

    public void show() {
        dialog.show();
    }
}
